package behavior.observer.self;

public class Demo {

    public static void main(String[] args) {

        WarfareSubject warfare = new ChiBiSubject("赤壁战争",100);
        WarfareObserver warfareObserver = new ChibiWar("魏国斥候");
        warfare.addObserver(warfareObserver);
        warfareObserver = new ChibiWar("吴国斥候");
        warfare.addObserver(warfareObserver);
        warfareObserver = new ChibiWar("蜀国斥候");
        warfare.addObserver(warfareObserver);

        for (int i = 0; i < 10000; i++) {
            Integer random = (int) (Math.random() * 10);
            if(warfare.getSoldierCount() <= 0){
                System.out.println("战争结束");
                warfare.deleteObservers();
                break;
            }
            if (random > 5) {
                warfare.add();
            } else {
                warfare.remove();
            }
        }
    }
}
